﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
namespace MillionArthurTool
{
    public partial class Form2 : Form
    {
        bool isUserAgentSet = false;
 
        private string szCookie;
        private string url = "http://web.million-arthurs.com/connect/web/?S=";
        [DllImport("wininet.dll", CharSet = CharSet.Auto, SetLastError = true)]
        public static extern bool InternetSetCookie(string lpszUrlName, string lbszCookieName, string lpszCookieData);


        public Form2(string szcookie)
        {
            szCookie = szcookie;
            InitializeComponent();
        }

        private void Form2_Load(object sender, EventArgs e)
        {
            InternetSetCookie(url, "S", szCookie);
            //bBrowser1.UserAgent = "User-Agent: Million/225 (c1lgt; c1lgt; 4.1.2) samsung/c1lgt/c1lgt:4.1.2/JZO54K/E210LKLJME2:user/release-keys GooglePlay";
            
        }

        private void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
        {
            if (!isUserAgentSet)
            {

                //webBrowser1.UserAgent = "User-Agent: Million/225 (c1lgt; c1lgt; 4.1.2) samsung/c1lgt/c1lgt:4.1.2/JZO54K/E210LKLJME2:user/release-keys GooglePlay";
                //cancel the current request

                e.Cancel = true;

                this.isUserAgentSet = true;


                //Navigate to the desired location using the custom user agent
                this.webBrowser1.Navigate(e.Url, e.TargetFrameName, null, "User-Agent: Million/225 (c1lgt; c1lgt; 4.1.2) samsung/c1lgt/c1lgt:4.1.2/JZO54K/E210LKLJME2:user/release-keys GooglePlay");

            }
        }

        private void webBrowser1_DocumentCompleted(object sender, WebBrowserDocumentCompletedEventArgs e)
        {
            //webBrowser1.Document.Cookie = "S=" + szCookie;
            this.isUserAgentSet = false;
        }

        private void button1_Click(object sender, EventArgs e)
        {

            webBrowser1.Navigate(url + szCookie);
        }

        private void button2_Click(object sender, EventArgs e)
        {
            webBrowser1.Navigate("http://web.million-arthurs.com/connect/web/event_sports");
        }
    }
}
